package celiasoft.itasalib.query;

import android.content.Context;
import celiasoft.itasalib.filegatherer.HTMLGatherer;
import celiasoft.itasalib.filegatherer.ImageGatherer;
import celiasoft.itasalib.filegatherer.XMLGatherer;
import celiasoft.itasalib.filegatherer.cache.FileCache;

public class RawQueryFactory {

	private final XMLGatherer _xmlGatherer;
	private final String _apikey;
	private final ImageGatherer _imgGatherer;
	private HTMLGatherer _htmlGatherer;
	
	private static RawQueryFactory _instance = null;
	
	public static RawQueryFactory getInstance(Context context, String apikey){
		
		if(_instance == null){
			_instance = new RawQueryFactory(context.getApplicationContext(), apikey);
		}
		
		return _instance;
	}
	
	private RawQueryFactory(Context context, String apikey) {
		
		FileCache cache = FileCache.Factory.Create(context);
		this._xmlGatherer = new XMLGatherer(cache);
		this._imgGatherer = new ImageGatherer(cache);
		this._htmlGatherer = new HTMLGatherer(cache);
		this._apikey = apikey;
	}

	public Query makeQuery(QueryType type){
		
		Query query = null;
		
		switch(type){
			case SHOW_ALL:
				query = new AllShowsQuery(_xmlGatherer, _apikey);
				break;
			case SHOW_SINGLE:
				query = new SingleShowQuery(_xmlGatherer, _apikey);
				break;
		/*	case SHOW_ALL_PAGES:
				query = new AllPageShowsQuery(_xmlGatherer, _apikey);
				break;*/
			case SHOW_THUMB:
				query = new ShowThumbQuery(_imgGatherer, _apikey);
				break;
			case SHOW_SEARCH:
				query = new SearchShowQuery(_xmlGatherer, _apikey);
				break;
	/*		case NEWS_ALL:
				query = new AllPageNewsQuery(_xmlGatherer, _apikey);
				break;*/
			case NEWS_ALL_PAGE:
				query = new AllPageNewsQuery(_xmlGatherer, _apikey);
				break;
			case NEWS_SINGLE:
				query = new SingleNewsQuery(_xmlGatherer, _apikey);
				break;
			case NEWS_SEARCH:
				query = new SearchNewsQuery(_xmlGatherer, _apikey);
				break;
			case SUBS_LIST_PAGES:
				query = new AllPageShowSubsQuery(_xmlGatherer, _apikey);
				break;
			case SUBS_SINGLE:
				query = new SingleShowSubQuery(_xmlGatherer, _apikey);
				break;
			case SUBS_SEARCH:
				query = new SearchShowSubsQuery(_xmlGatherer, _apikey);
				break;
			case USER_THIS:
				query = new OwnUserQuery(_xmlGatherer, _apikey);
				break;
			case USER_SINGLE:
				query = new SingleUserQuery(_xmlGatherer, _apikey);
				break;
			case LOGIN:
				query = new LoginQuery(_xmlGatherer, _apikey);
				query.cacheResult(false);
				break;
			case MYITASA_SHOWS:
				query = new MyItasaShowsQuery(_xmlGatherer, _apikey);
				query.cacheResult(false);
				break;
			case MYITASA_LAST_SUBS:
				query = new MyItasaLastSubsQuery(_xmlGatherer, _apikey);
				query.cacheResult(false);
				break;
			case MYITASA_NEXT_SHOWS:
				query = new MyItasaNextEpisodesQuery(_xmlGatherer, _apikey);
				query.cacheResult(false);
				break;
			case MYITASA_ADD_SHOW:
				query = new MyItasaAddShowQuery(_xmlGatherer, _apikey);
				query.cacheResult(false);
				break;
			case MYITASA_REMOVE_SHOW:
				query = new MyItasaRemoveShowQuery(_xmlGatherer, _apikey);
				query.cacheResult(false);
				break;	
			case SHOWS_CALENDAR:
				query = new CalendarQuery(_htmlGatherer);
				break;	
			case TRANSLATIONS_STATUS:
				query = new TranslationsStatusQuery(_htmlGatherer);
				break;		
		}
		
		return 	query;		
		
	}

}
